package com.example.mardan.views;

import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.mardan.entity.BookEntity;
import com.example.read.databinding.ActivityBookDetailsBinding;
import com.google.gson.Gson;

public class DetailsActivity extends AppCompatActivity {
      private ActivityBookDetailsBinding binding ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityBookDetailsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Intent intent = getIntent() ;
        String getBook = intent.getStringExtra("bookData");
        Gson gson = new Gson() ;
        BookEntity.ResultData.BookData book = gson.fromJson(getBook, BookEntity.ResultData.BookData.class);
        Glide.with(this)
                .load(book.getImg())
                .into(binding.bookImg);
        binding.bookName.setText(book.getTitle());
        binding.bookType.setText(book.getCatalog());
        binding.bookItr.setText(book.getSub2());
    }


    private void openWebsite(String uri) {
        String url = uri; // 替换成你要跳转的网址
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            // 没有可以处理此Intent的应用程序
            Toast.makeText(this, "无法打开网页，请检查设备是否安装了浏览器", Toast.LENGTH_SHORT).show();
        }
    }

    //查看更多
    private void onMoreClicked(String bookItr2) {
        new AlertDialog.Builder(this)
                .setTitle("书籍详细介绍")
                .setMessage(bookItr2)
                .setPositiveButton(android.R.string.ok, null)
                .show();
    }
}